package model

import (
	"time"
)

// Order 订单模型
type Order struct {
	BaseModel
	OrderNo      string    `json:"order_no" gorm:"size:50;not null;unique"`
	UserID       uint      `json:"user_id" gorm:"not null"`
	TotalAmount  float64   `json:"total_amount" gorm:"type:decimal(10,2);not null"`
	Status       int       `json:"status" gorm:"default:0"`     // 0: 待付款, 1: 待发货, 2: 待收货, 3: 已完成, 4: 已取消, 5: 已退款
	PayStatus    int       `json:"pay_status" gorm:"default:0"` // 0: 未支付, 1: 已支付
	PayTime      time.Time `json:"pay_time"`
	PayMethod    int       `json:"pay_method" gorm:"default:0"` // 0: 未选择, 1: 微信支付, 2: 支付宝, 3: 银行卡
	PayAmount    float64   `json:"pay_amount" gorm:"type:decimal(10,2);default:0"`
	Address      string    `json:"address" gorm:"size:255"`
	Receiver     string    `json:"receiver" gorm:"size:50"`
	Phone        string    `json:"phone" gorm:"size:20"`
	Remark       string    `json:"remark" gorm:"size:255"`
	ShipStatus   int       `json:"ship_status" gorm:"default:0"` // 0: 未发货, 1: 已发货, 2: 已收货
	ShipTime     time.Time `json:"ship_time"`
	ShipNo       string    `json:"ship_no" gorm:"size:50"`
	ShipCompany  string    `json:"ship_company" gorm:"size:50"`
	FinishTime   time.Time `json:"finish_time"`
	CancelTime   time.Time `json:"cancel_time"`
	CancelReason string    `json:"cancel_reason" gorm:"size:255"`
}

// TableName 表名
func (Order) TableName() string {
	return "orders"
}

// OrderItem 订单项模型
type OrderItem struct {
	BaseModel
	OrderID      uint    `json:"order_id" gorm:"not null"`
	ProductID    uint    `json:"product_id" gorm:"not null"`
	ProductName  string  `json:"product_name" gorm:"size:100;not null"`
	ProductImage string  `json:"product_image" gorm:"size:255"`
	Price        float64 `json:"price" gorm:"type:decimal(10,2);not null"`
	Quantity     int     `json:"quantity" gorm:"not null"`
	TotalAmount  float64 `json:"total_amount" gorm:"type:decimal(10,2);not null"`
	Attributes   string  `json:"attributes" gorm:"type:text"`
}

// TableName 表名
func (OrderItem) TableName() string {
	return "order_items"
}

// Payment 支付记录
type Payment struct {
	BaseModel
	OrderID      uint      `json:"order_id" gorm:"not null"`
	PaymentNo    string    `json:"payment_no" gorm:"size:100;not null;unique"`
	PayMethod    int       `json:"pay_method" gorm:"default:0"` // 0: 未选择, 1: 微信支付, 2: 支付宝, 3: 银行卡
	PayAmount    float64   `json:"pay_amount" gorm:"type:decimal(10,2);not null"`
	Status       int       `json:"status" gorm:"default:0"` // 0: 未支付, 1: 已支付, 2: 支付失败, 3: 已退款
	PaidAt       time.Time `json:"paid_at"`
	FailReason   string    `json:"fail_reason" gorm:"size:255"`
	RefundAt     time.Time `json:"refund_at"`
	RefundNo     string    `json:"refund_no" gorm:"size:100"`
	RefundReason string    `json:"refund_reason" gorm:"size:255"`
}

// TableName 表名
func (Payment) TableName() string {
	return "payments"
}
